using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using WebAndLoadTestPluginsAndRules.Common;

namespace HtmlTagInnerTextTests.Common
{
    /// <summary>
    ///This is a test class for FilterFactoryTest and is intended
    ///to contain all FilterFactoryTest Unit Tests
    ///</summary>
    [TestClass]
    public class FilterFactoryTest
    {
        /// <summary>
        ///A test for GetFilter
        ///</summary>
        [TestMethod]
        public void GetFilter_WhenFilterMethodStartsWith_EnsureReturnsStartsWithFilter()
        {
            // Arrange
            FilterFactory target = new FilterFactory(); 
            const string filter = "filter";
            const FilterMethod filterMethod = FilterMethod.StartsWith;
            const bool ignoreCase = false;
            
            // Act
            Filter actual = target.GetFilter(filter, filterMethod, ignoreCase);
            
            // Assert
            Assert.IsInstanceOfType(actual, typeof(StartsWithFilter));
        }
        /// <summary>
        ///A test for GetFilter
        ///</summary>
        [TestMethod]
        public void GetFilter_WhenFilterMethodExactMatch_EnsureReturnsExactMatchFilter()
        {
            // Arrange
            FilterFactory target = new FilterFactory();
            const string filter = "filter";
            const FilterMethod filterMethod = FilterMethod.ExactMatch;
            const bool ignoreCase = false;

            // Act
            Filter actual = target.GetFilter(filter, filterMethod, ignoreCase);

            // Assert
            Assert.IsInstanceOfType(actual, typeof(ExactMatchFilter));
        }
        /// <summary>
        ///A test for GetFilter
        ///</summary>
        [TestMethod]
        public void GetFilter_WhenFilterMethodRegex_EnsureReturnsRegexFilter()
        {
            // Arrange
            FilterFactory target = new FilterFactory();
            const string filter = "filter";
            const FilterMethod filterMethod = FilterMethod.Regex;
            const bool ignoreCase = false;

            // Act
            Filter actual = target.GetFilter(filter, filterMethod, ignoreCase);

            // Assert
            Assert.IsInstanceOfType(actual, typeof(RegexFilter));
        }
        /// <summary>
        ///A test for GetFilter
        ///</summary>
        [TestMethod]
        public void GetFilter_WhenFilterMethodInvalid_EnsureThrowsArgumentException()
        {
            // Arrange
            FilterFactory target = new FilterFactory();
            const string filter = "filter";
            const FilterMethod filterMethod = (FilterMethod) (-1);
            const bool ignoreCase = false;

            // Act
            Action action = ()=> target.GetFilter(filter, filterMethod, ignoreCase);

            // Assert
            AssertHelpers.ThrowsArgumentException<ArgumentException>(action, "filterMethod");
        }

    }
}